#include <iostream>
#include "Reactor.hpp"
#include "Listener.hpp"
#include "Connection.hpp"
int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }
    int port = std::stoi(argv[1]);
    // Listener listener(port);
    // listener.Init();
    // connection_t conn = std::make_shared<Connection>(listener.ListenSockfd());
    // conn->SetEvents(EPOLLIN|EPOLLET);
    // conn->InsertMethod([&](){
    //     InetAddr peer;
    //     std::cout<<"将要获取连接.."<<std::endl;
    //     int newsockfd = listener.Accepter(&peer);
    //     std::cout<<"获取新连接newsockfd: "<<newsockfd<<std::endl;
    //     //newsockfd TODO
    //     conn->SetPeerAddrInfo(peer);
    // },nullptr,nullptr);
    connection_t conn = std::make_shared<Listener>(port);
    Reactor epoll_server;
    epoll_server.Init();
    std::cout<<"------------"<<std::endl;
    epoll_server.InsertConnection(conn);
    epoll_server.Loop();
    return 0;
}